package com.tencent.cloud.uikit.ui.drawable;

import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * @author saixiang
 * @date 2018/8/23
 */
public class RoundRectDrawable extends Drawable {

    private Paint mPaint;
    private RectF mRectF;
    private int mRound;

    public RoundRectDrawable(){
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setColor(0xFFA4B5D5);
        mPaint.setStrokeWidth(3);
        mPaint.setStyle(Paint.Style.STROKE);
    }
    @Override
    public void draw(@NonNull Canvas canvas) {
        canvas.drawRoundRect(mRectF, mRound, mRound, mPaint);
    }

    @Override
    public void setAlpha(int alpha) {
        mPaint.setAlpha(alpha);
    }

    public void setRound(int round) {
        mRound = round;
    }

    @Override
    public void setColorFilter(@Nullable ColorFilter colorFilter) {

    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }

    @Override
    public void setBounds(int left, int top, int right, int bottom) {
        mRectF = new RectF(left, top, right, bottom);
        super.setBounds(left, top, right, bottom);
    }
}
